<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/16 0016
  Time: 上午 10:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    <style>
        .layui-table-view{
            margin-bottom: 120px;
        }
    </style>
</head>
<body>
<br><br><br>
<div>
    <%--<select name="state" id="state" lay-verify="" style="margin-top:0rem !important;font-size: 1.3rem;--%>
    <%--height: 2.1rem;width: 6rem; line-height:2rem;margin-left: 3rem"--%>
    <%--onchange="seachOrder()">--%>
    <%--<option value="" selected="selected">全部</option>--%>
    <%--<option value="0" <c:if test="${key eq '0'}">selected="selected"</c:if> >未上架</option>--%>
    <%--<option value="1" <c:if test="${key eq '1'}">selected="selected"</c:if>>上架中</option>--%>
    <%--<option value="2" <c:if test="${key eq '2'}">selected="selected"</c:if>>已下架</option>--%>
    <%--</select>--%>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i>
    </a>
</div>
<script>
    function seachOrder() {
        window.location.href='/shop/commodityList?key='+$("#state").val();
    }
</script>
<div class="layui-form">
    <form class="layui-form" action="">
        <table class="layui-table" >
            <thead>
            <tr>
                <th>名称</th>
                <th>票类型</th>
                <th>原价</th>
                <%--<th>库存</th>--%>
                <th>现价</th>
                <%--<th>销量</th>--%>
                <%--<th>更新时间</th>--%>
                <%--<th>分销利润</th>--%>
                <th>类别</th>
                <%--<th>服务说明</th>--%>
                <th>状态</th>
                <th>抢购时间</th>
                <th>轮播图</th>
                <%--<th>设置图片分享海报图片的窗口</th>--%>
                <th>商品详情</th>
                <th>自定义标签</th>
                <th>关联优惠券</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageUtil.list}" var="rl">
                <tr>
                    <td>${rl.memberName}</td>
                    <td>${rl.memberTel}</td>
                    <td>${rl.orderId}</td>
                        <%--<td>${rl.inventory}</td>--%>
                    <td>${rl.shopId}</td>
                        <%--<td>${rl.salNum}</td>--%>
                        <%--<td>${rl.modifiedTime}</td>--%>
                        <%--<td>分销利润</td>--%>
                    <td>类别 古城 热门</td>
                        <%--<td>${rl.description}</td>--%>
                    <%--<td><c:choose>--%>
                        <%--<c:when test ="${rl.state eq 0}">未上架</c:when>--%>
                        <%--<c:when test ="${rl.state eq 1}">上架中</c:when>--%>
                        <%--<c:when test ="${rl.state eq 2}">已下架</c:when>--%>
                    <%--</c:choose></td>--%>
                    <td style="width: 180px;">
                        <button type="button" class="layui-btn" onclick="update('${rl.id}');">修改</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" class="layui-btn layui-btn-danger" onclick="delProduct('${rl.id}');">删除</button>
                    </td>

                </tr>
            </c:forEach>
            </tbody>
        </table>
    </form>


    <div id="page"></div>
    <script>
        function setSlide(id){
            layui.use('layer',function () {
                layer.open({
                    type: 2,
                    area: ['80%', '80%'],
                    offset: '20px',
                    shadeClose:true,
                    content: '/shop/toCommoditySlideShow?commodity='+id,
                    end:function () {
                        console.log("页面要刷新");
                        window.location.reload();
                    }
                });
            });
        }
        layui.use(['laypage', 'layer'], function(){
            var laypage = layui.laypage
                ,layer = layui.layer;

            //完整功能
            laypage.render({
                elem: 'page'
                ,count: ${pageUtil.totalRows}
                ,curr:${pageUtil.currentPage}
                ,hash:true
                ,limits:false
                ,layout: ['count', 'prev', 'page', 'next',  'refresh', 'skip']
                ,jump: function(obj,first){
                    console.log(obj);
                    //首次不执行
                    if(!first){
                        //do something
                        window.location.href="/shop/commodityList?page="+obj.curr+"&limit="+obj.limit+"&key=${key}";
                    }

                }
            });

        });


    </script>
</div>
<script>
    layui.use('layer', function(){
        var layer = layui.layer;
        $(document).on('click','#add',function(){
            layer.open({
                type: 2,
                area: ['90%', '90%'],
                offset: '20px',
                shadeClose:true,
                content: '/shop/commodityEdit?commodity=',
                end:function () {
                    console.log("页面要刷新");
                    window.location.reload();
                }
            });
        });
    });
    /*修改商品*/
    function update(id) {
        layer.open({
            type: 2,
            area: ['90%', '90%'],
            offset: '20px',
            shadeClose:true,
            content: '/shop/commodityEdit?id='+id,
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });
    }

    /*商品详情*/
    function commodityMessage() {

        layer.open({
            type: 2,
            area: ['90%', '90%'],
            offset: '20px',
            shadeClose:true,
            content: '/shop/commodityMessage?commodityId='+id,
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });
    }




    function linkConpon(id) {
        layer.open({
            type: 2,
            area: ['70%', '70%'],
            offset: '20px',
            shadeClose:true,
            content: '/shop/coupon?id='+id,
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });


    }

    /*删除商品*/
    function delProduct(id) {
        $.ajax({
            url:'/shop/delCommodity',
            type:'POST', //GET
            async:true,    //或false,是否异步
            data:{
                id:id,
            },
            timeout:5000,    //超时时间
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend:function(xhr){
                /*console.log(xhr)
                 console.log('发送前')*/
            },
            success:function(dataA){
                console.log(dataA);
                if (dataA.code=='000000'){
                    window.location.reload();
                    // 获得frame索引
                }else {
                    layer.msg("删除失败",{time:1000,icon: 5});
                }
            },
            error:function(xhr,textStatus){
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete:function(){
                //console.log('结束')
            }
        })
    }
    /*设置商品轮播图*/
    function commodityGame(id,gameId){
        layer.open({
            type: 2,
            area: ['90%', '80%'],
            offset: '20px',
            shadeClose:true,
            title:'选择游戏',
            content: '/shop/commodityGame?commodityId='+id+"&gameId="+gameId,
            end:function () {
                console.log("页面要刷新");
                //window.location.reload();
            }
        });
    }
    /*设置商品信息*/
    function commodityMessage(id){
        layer.open({
            type: 2,
            area: ['450', '90%'],
            offset: '20px',
            shadeClose:true,
            title:'商品信息设置  图片建议尺寸  宽425px',
            content: '/shop/commodityMessage?commodityId='+id,
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });
    }

    /**
     * 商品详情  commodityParticulars
     */
    function commodityParticulars(id){
        layer.open({
            type: 2,
            area: ['450', '80%'],
            offset: '20px',
            shadeClose:true,
            title:'商品详情设置  图片建议尺寸  宽425px',
            content: '/shop/commodityParticulars?commodityId='+id,
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });
    }
    /*门票标签*/
    function brandLabel(id) {
        layer.open({
            type: 2,
            area: ['90%', '80%'],
            offset: '20px',
            shadeClose:true,
            title:'标签',
            content: '/shop/brandLabel?commodityId='+id,
            end:function () {
                console.log("页面要刷新");
                //window.location.reload();
            }
        });
    }
</script>
</body>
</html>
